#ifndef INI_FILE_READER_H
#define INI_FILE_READER_H

#include <inifilerd/IniFileParser.h>
#include <inifilerd/IniFileHandler.h>
#include <inifilerd/IniFileLexer.h>
#include <fstream>

namespace IniFile {

class Reader
{
    std::ifstream inputStream_;
    Lexer lexer_;
    Parser parser_;
public:
	Reader(Handler *handler) :
        lexer_(&inputStream_, handler),
        parser_(&lexer_, handler)
	{
		inputStream_.exceptions(std::ifstream::badbit);
		// ---std::ifstream::failbit is bad idea when handling EOFs
	}
	void open(const char *filename)
	{
		inputStream_.open(filename);
		if (inputStream_.fail())
			throw std::fstream::failure(filename);
	}
	void close()
	{
		inputStream_.close();
	}
	void rewind()
	{
		inputStream_.seekg(0, inputStream_.beg);
		inputStream_.clear();
	}
	void parse()
	{
        parser_.parse();
	}
};

} // namespace IniFile

#endif
